<?php
require_once '../sub/init.php';
if(!is_weixin())alert('请用打开微信操作','-1');
if(!ifint($uid))alert('UID不正确','-1');
if (empty($server_openid) && is_weixin()){$server_openid=wx_get_openid();}
require_once ZEAI.'sub/conn.php';
require_once ZEAI.'m/header.php';
if(!ifint($u) || empty($p) || empty($submitok))alert('非法操作1','-1');
$row = $db->ROW(__TBL_ADMIN__,"password","id=".$u,"name");
if ($row){
	$pwd=$row['password'];
	$pwd=md5($pwd.'ZEAI.cn');
	if($pwd!=$p)alert('非法操作2','-1');
}else{alert('非法操作3','-1');}
if($submitok == 'ewm'){
	$row = $db->ROW(__TBL_USER__,"nickname,openid"," openid<>'' AND id=".$uid,"name");
	if ($row){
		$nickanme = trimhtml(dataIO($row['nickname'],'out'));
		$openid   = trimhtml($row['openid']);
		alert_adm("当前用户【".$nickanme."（uid:".$uid."）】已经绑定了其他微信，请解绑后再来操作<br>openid：".$openid,"-1");
	}else{
		$row = $db->ROW(__TBL_USER__,"id,nickname"," openid<>'' AND openid='".$server_openid."'","name");
		if ($row){
			$uid2 = $row['id'];
			$nickanme2 = trimhtml(dataIO($row['nickname'],'out'));
			alert("当前微信号已被<font class=\"C00f\">".$nickanme2."（uid:".$uid2."）</font>占用，请解绑后再来绑定<br>openid：".$server_openid,"-1");
		}
		$db->query("UPDATE ".__TBL_USER__." SET openid='$server_openid' WHERE id=".$uid);
		alert_adm("恭喜【uid:".$uid."】微信号绑定成功<br>openid：".$server_openid,mHref('my'));
	}
}?>